
#pragma once

#include <stdio.h>
#include <string>
#include <ttg/services.h>

//Parses command line arguments.
//In case of error terminates program.
class ArgsParser
{
	private:
		size_t n;
		size_t thread_count;
		//Prints help.
		inline void printHelp()
		{
			printf("Usage: Fibonacci.exe [N] [THREAD_COUNT]\n\n");
			printf("	Where:\n");
			printf("		N - order number of required Fibonacci number. Default value = 100.\n");
			printf("		THREAD_COUNT - Count of available performers. Default value = count of cores.\n");
		}
	public:
		//Parses command line arguments.
		//In case of error/special options prints help and terminates program.
		ArgsParser(int argc, char **argv)
		{
			if (argc == 1 || argc == 3 ||
				(argc == 2 && argv[1] != std::string("-h") &&
							  argv[1] != std::string("--help") &&
							  argv[1] != std::string("/?")))
			{
				n = argc == 1 ? 100 : atoi(argv[1]);
				thread_count = argc == 3 ? atoi(argv[2]) : 1;// ttg::services::CPUAnalyzer::getRef()->getCoreCount();
			}
			else
			{
				printHelp();
				exit(0);
			}
		}
		//Returns order number of required fibonacci number.
		inline size_t getN() const
		{ return n; }
		inline size_t getThreadCount() const
		{
			return thread_count;
		}
};
